var gulp=require('gulp'),
	browserSync = require('browser-sync'),
	nodemon = require('gulp-nodemon');


gulp.task('node', function (cb) {
	
	var called = false;
	return nodemon({
		script: 'app.js',
		ext: 'js'
	})
	.on('start', function () {
    if (!called) {
	      called = true;
	      cb();
	    }
	  })
  .on('restart', function () {
    setTimeout(function () {
      browserSync.reload({ stream: false });
    }, 1000);
  });
});

gulp.task('server', ['node'], function () {
  browserSync.init(null, {
    proxy: 'http://localhost:2888',
    files: ['./static/*.*','./app.js'],
    browser: 'chrome',
    notify: false,
    port: 2889
  });
  // gulp.watch("./app.js").on('change',browserSync.reload);
  // gulp.watch("./static/*.*").on('change',browserSync.reload);

});


gulp.task('default', [
  'server'
]);